import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import router from './router'
import store from './store'
import {initMenu} from "@/utils/menu";
import {deleteRequest, getRequest, putRequest} from "@/utils/api";
import axios from "axios";
Vue.config.productionTip = false;

Vue.prototype.putRequest = putRequest;
Vue.prototype.getRequest = getRequest;
Vue.prototype.deleteRequest = deleteRequest;
Vue.use(ElementUI)
import Avue from '@smallwei/avue';
import '@smallwei/avue/lib/index.css';
import Sortable from 'sortablejs';
Vue.use(Avue);
router.beforeEach((to,from,next)=>{
  if (window.sessionStorage.getItem('tokenStr')){
     initMenu(router,store)
      next();
     if(!window.sessionStorage.getItem('user')){
         //获取用户信息
      axios({
          method:'get',
          url:'/api/admin/info'
      }).then(res=>{
          window.sessionStorage.setItem('user',JSON.stringify(res.data));
          next()
      })
     }
  }else {
      if( to.path == '/' ){
          next();
      }else {
          next('/?redirect'+to.path)
      }
      next();
  }
})
new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')

